package com.cskaoyan.controller.stage;

import com.cskaoyan.mapper.UserMapper;
import com.cskaoyan.model.Address;
import com.cskaoyan.model.bo.BaseParamBO;
import com.cskaoyan.model.bo.SaveAddressDetailBO;
import com.cskaoyan.model.vo.AddressDataVO;
import com.cskaoyan.model.vo.CollectorDataVO;
import com.cskaoyan.model.vo.CollectorRespVO;
import com.cskaoyan.model.vo.ExceptionVO;
import com.cskaoyan.service.AddressService;
import com.cskaoyan.service.CollectorService;
import com.cskaoyan.service.WxAddressService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @program: 微信小程序
 * @description:
 * @author: Wangtianhao
 * @create: 2022-05-09 14:07
 **/

@RestController
@RequestMapping("wx/address")
public class WxAddressController {

    @Autowired
    WxAddressService wxAddressService;

    @Autowired
    UserMapper userMapper;


    /*
     * description 获取地址列表
     * @author Wangtianhao
     * @date 2022-05-09 19:39
     */
    @GetMapping("list")
    public CollectorRespVO addressList(BaseParamBO param) {
        AddressDataVO addressDataVO = wxAddressService.queryList(param);
        return CollectorRespVO.ok(addressDataVO);
    }

    /*
     * description 获取地址信息
     * @author Wangtianhao
     * @date 2022-05-09 19:39
     */
    @GetMapping("detail")
    public CollectorRespVO addressDetail(Integer id) {
        Address addressDataVO = wxAddressService.getAddressDetail(id);
        return CollectorRespVO.ok(addressDataVO);
    }

    /*
     * description 保存地址信息到数据库
     * @author Wangtianhao
     * @date 2022-05-09 19:40
     */
    @PostMapping("save")
    public CollectorRespVO saveAddressDetail(@RequestBody SaveAddressDetailBO saveAddressDetailBO) {
        wxAddressService.saveAddressDetail(saveAddressDetailBO);
        Integer id = saveAddressDetailBO.getId();
        return CollectorRespVO.ok(id);
    }

    /*
     * description
     * @author Wangtianhao
     * @date 2022-05-09 19:40
     */
    @PostMapping("delete")
    public CollectorRespVO deleteAddressDetail(@RequestBody Address address) {
        Integer id = address.getId();
        wxAddressService.deleteAddressDetail(id);
        return CollectorRespVO.ok();
    }

}
